<?php

namespace App\Admin\Repositories;

use App\Models\OrgTeamOwner as Model;
use Dcat\Admin\Repositories\EloquentRepository;

class OrgTeamOwner extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    public function getOwnerListByTeamId(int $teamId) : array
    {
        return $this->eloquentClass::query()->where('team_id', $teamId)->get()->toArray();
    }

    public function getTeamListByOwnerUidAndDepartmentIds(int $ownerUid, array $departmentIds = []) : object
    {
        $rs = $this->eloquentClass::query()->where('owner_uid', $ownerUid);
        if ($departmentIds){
            $rs = $rs->whereIn('department_id', $departmentIds, 'or');
        }
        return $rs->get();
    }

    public function getTeamListByOwnerUid(int $ownerUid) : object
    {
        return $this->eloquentClass::query()->where('owner_uid', $ownerUid)->get();
    }

    public function getTeamListByOwnerUidAndDepartmentId(int $ownerId, int $departmentId) : object
    {
        return $this->eloquentClass::query()
            ->where('owner_uid', $ownerId)
            ->where('department_id', $departmentId)
            ->get();
    }
}
